package club.emergency.wechat.mistake_collection.operate.consumer.controller;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.utils.JsonConvert;
import club.emergency.wechat.mistake_collection.operate.consumer.service.MistakeCollectionOperateConsumer;
import club.emergency.wechat.model.mistake_collection.MistakeCollection;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.mistake_collection.operate.consumer.controller
 * Date: 2018/12/23
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Api("错题操作接口")
@RestController
@RequestMapping("/mistake-collection-operate")
public class MistakeCollectionController {

    private MistakeCollectionOperateConsumer mistakeCollectionOperateConsumer;

    public MistakeCollectionController(MistakeCollectionOperateConsumer mistakeCollectionOperateConsumer) {
        this.mistakeCollectionOperateConsumer = mistakeCollectionOperateConsumer;
    }

    @ApiOperation("新增错题")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "人员Id", name = "staffId", required = true, dataType = "long", paramType = "query"),
            @ApiImplicitParam(value = "试题id", name = "questionId", required = true, dataType = "long", paramType = "query"),
            @ApiImplicitParam(value = "试题题干", name = "questionContent", required = true, dataType = "long", paramType = "query"),
            @ApiImplicitParam(value = "用户选择的错误选项", name = "wrongChoiceOption", required = true, dataType = "long", paramType = "query"),
            @ApiImplicitParam(value = "用户选择的错误选项内容", name = "wrongChoiceOptionContent", required = true, dataType = "long", paramType = "query"),
    })
    @PostMapping("/save")
    public ResponseEntity save(
            @RequestParam("staffId") Long staffId,
            @RequestParam("questionId") Long questionId,
            @RequestParam("questionContent") String questionContent,
            @RequestParam("wrongChoiceOption") String wrongChoiceOption,
            @RequestParam("wrongChoiceOptionContent") String wrongChoiceOptionContent
    ) {
        MistakeCollection mistakeCollection = new MistakeCollection();
        mistakeCollection.setStaffId(staffId);
        mistakeCollection.setQuestionId(questionId);
        mistakeCollection.setQuestionContent(questionContent);
        mistakeCollection.setWrongChoiceOption(wrongChoiceOption);
        mistakeCollection.setWrongChoiceOptionContent(wrongChoiceOptionContent);
        return new JsonConvert<ResponseEntity>().jsonDecode(mistakeCollectionOperateConsumer.save(mistakeCollection), ResponseEntity.class);
    }

    @ApiOperation("消灭错题")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "错题id", name = "id", required = true, dataType = "long", paramType = "query")
    })
    @PostMapping("/eliminate")
    public ResponseEntity eliminate(
            @RequestParam("id") Long id
    ) {
        return new JsonConvert<ResponseEntity>().jsonDecode(mistakeCollectionOperateConsumer.eliminate(id), ResponseEntity.class);
    }
}
